using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GameFrameWork;

/// <summary>
/// 酸液攻击策略 - 发射酸液弹，造成持续伤害
/// </summary>
public class AcidSpitAttack : AttackStrategyBase
{
    private string m_ProjectileId;
    private readonly List<IAttackEffect> m_Effects = new List<IAttackEffect>();

    public AcidSpitAttack(SkillData data)
    {
        AttackData = data;
    }

    /// <summary>
    /// 设置投射物ID
    /// </summary>
    public AcidSpitAttack SetProjectile(string projectileId)
    {
        m_ProjectileId = projectileId;
        return this;
    }

    /// <summary>
    /// 添加攻击效果
    /// </summary>
    public AcidSpitAttack AddEffect(IAttackEffect effect)
    {
        if (effect != null && !m_Effects.Contains(effect))
        {
            m_Effects.Add(effect);
        }
        return this;
    }

    public override void Execute(Entity target)
    {
        base.Execute(target);

        if (target == null)
        {
            Logger.LogWarning("AcidSpitAttack", $"{Owner?.name} 攻击目标无效");
            return;
        }

        if (AttackData == null || AttackData.BulletData == null)
        {
            Logger.LogError("AcidSpitAttack", $"{Owner?.name} 缺少子弹数据");
            return;
        }

        // 创建酸液弹
        var bulletData = AttackData.BulletData;
        var bullet = BulletPool.Instance.GetBullet(bulletData);
        
        if (bullet == null)
        {
            Logger.LogError("AcidSpitAttack", $"无法获取子弹：{bulletData.BulletType}");
            return;
        }

        // 设置子弹位置
        Vector3 startPos = Owner.transform.position;
        if (bulletData.OffVec3 != Vector3.zero)
        {
            startPos += bulletData.OffVec3;
        }
        bullet.transform.position = startPos;

        // 创建移动策略
        var movement = MoveStrategyFactory.Create(bulletData.MoveData);
        bullet.Initialize(owner: Owner, movement: movement);

        // 应用效果到子弹（如果有）
        // 注意：这里需要根据实际的Bullet类实现来添加效果
        // 如果Bullet类支持效果，可以在这里添加
        // foreach (var effect in m_Effects)
        // {
        //     bullet.AddEffect(effect);
        // }

        Logger.Log("AcidSpitAttack", $"{Owner?.name} 发射酸液弹攻击 {target.name}");
    }

    public override bool CheckCondition()
    {
        return base.CheckCondition() && 
               AttackData != null && 
               AttackData.BulletData != null;
    }
}
